package com.voicechat.firstmet.activity;

import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.text.Editable;
import android.text.InputFilter;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.voicechat.firstmet.R;
import com.voicechat.firstmet.base.BaseActivity;
import com.voicechat.firstmet.utils.StatusBarUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @ProjectName: FirstMet
 * @Package: com.voicechat.firstmet.activity
 * @ClassName: BlindDateDemandRemarks
 * @Description: 备注activity
 * @Author: ljp
 * @CreateDate: 2019/1/17 17:13
 * @Version: 1.0
 */
public class BlindDateDemandRemarksActivity extends BaseActivity {
    @BindView(R.id.linear_back)
    LinearLayout linearBack;
    @BindView(R.id.tv_contact)
    TextView tvContact;
    @BindView(R.id.et_back)
    EditText etBack;
    @BindView(R.id.tv_sum)
    TextView tvSum;
    @BindView(R.id.radio_vip_renew)
    CheckBox radioVipRenew;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.tv_recharge)
    TextView tvRecharge;
    private String remarks;
    private String address;
    private int number;
    private String flag;//1 备注页面  2地址页面
    private String TAG = "BlindDateDemandRemarksActivity";

    @Override
    protected int setStatusBarColor() {
        return 0;
    }

    @Override
    protected boolean isSettingStatusBarText() {
        return false;
    }

    @Override
    protected int loadLayout() {
        return R.layout.activity_remarks;
    }

    @Override
    protected void initLayout(Bundle savedInstanceState) {
        ButterKnife.bind(this);
        //透明状态栏
        StatusBarUtils.Full(this);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            this.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        }
        flag = getIntent().getStringExtra("flag");
        remarks = getIntent().getStringExtra("remark");
        address = getIntent().getStringExtra("address");
        number = getIntent().getIntExtra("number", 0);
        initView();

    }

    private void initView() {
        tvSum.setText("0/" + number);
        if (flag.equals("1")) {
            if (!TextUtils.isEmpty(remarks)) {
                etBack.setText(remarks);
                tvSum.setText(remarks.length() + "/" + number);
            }
            tvTitle.setText("填写备注");
        } else {
            if (!TextUtils.isEmpty(address)) {
                etBack.setText(address);
                tvSum.setText(address.length() + "/" + number);
            }
            tvTitle.setText("填写约会地点");
        }
        InputFilter[] filters = {new InputFilter.LengthFilter(number)};
        etBack.setFilters(filters);
        etBack.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }

            @Override
            public void afterTextChanged(Editable s) {
                tvSum.setText(s.length() + "/" + number);
            }
        });
    }

    @OnClick({R.id.linear_back, R.id.tv_contact})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.linear_back:
                finish();
                break;
            case R.id.tv_contact:
                setRemarks();
                break;
        }
    }

    private void setRemarks() {
        String trim = etBack.getText().toString().trim();
        if (TextUtils.isEmpty(trim)) {
            toast_MakeText("请" + tvTitle.getText().toString());
            return;
        }
        if (!radioVipRenew.isChecked()) {
            toast_MakeText("请先同意协议");
            return;
        }
        Intent intent = new Intent(activity, BlindDateDemandActivity.class);
        intent.putExtra("flag", flag);
        if (flag.equals("1")) {
            intent.putExtra("remark", trim);
        } else {
            intent.putExtra("address", trim);
        }
        setResult(RESULT_OK, intent);
        finish();
    }

    @OnClick(R.id.tv_recharge)
    public void onClick() {
        Intent intent = new Intent(activity, WebPageActivity.class);
        intent.putExtra("url","file:///android_asset/web/shareBestie.html");
        intent.putExtra("title","共享闺蜜服务协议");
        startActivity(intent);
    }
}
